package com.example.administrator.nurse.present;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.model.CommonViewHolder;
import com.example.administrator.nurse.model.bean.money_check_bean;
import com.example.administrator.nurse.util.recyclerViewHelper;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.text.SimpleDateFormat;
import java.util.Date;

import jjobes.SlideDateTimeListener;
import jjobes.SlideDateTimePicker;

/**
 * Created by huhaichao on 2017/1/12.
 */

public class WorkStatisticsActivity extends BaseActivity{

    private recyclerViewHelper<money_check_bean> recyclerViewHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        configCommonHeader(WorkStatisticsActivity.this, "工作统计", 1);
        initView();
    }

    @Override
    protected int setLayotId() {
        return R.layout.work_statistics_main;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }
    private void initView(){
        LinearLayout container = (LinearLayout) f(R.id.container);

        recyclerViewHelper= new recyclerViewHelper<money_check_bean>(this, (XRecyclerView) findViewById(R.id.recyclerView))
                .withAdapter(R.layout.work_statistics_bean)
                .withTestData(new recyclerViewHelper.TestDataInterface() {
                    @Override
                    public money_check_bean addTestData(int i) {
                        money_check_bean bean = new money_check_bean();

                        bean.setBed("0" + i);
                        bean.setName("胡海潮");
                        bean.setAge("22岁");
                        bean.setSex("男");
                        bean.setStartTime("2016-2-10");



                        bean.setRoom1("02");
                        bean.setWorkName("医嘱执行");
                        return bean;
                    }
                })
                .withLoadMore(new recyclerViewHelper.loadMoreListener() {
                    @Override
                    public void loadMore() {

                    }
                })
                .withBindView(new recyclerViewHelper.BindViewListener() {
                    @Override
                    public void bindView(CommonViewHolder holder, final int position) {
                        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(WorkStatisticsActivity.this,MoneyItemActivty.class);
                                //intent.putExtra("data",recyclerViewHelper.list.get(position));
                                startActivity(intent);
                            }
                        });
                        TextView room1,bed,name,sex,age,workname,starttime;

                        room1 = holder.getTextView(R.id.room1);
                        bed = holder.getTextView(R.id.bed);
                        name = holder.getTextView(R.id.name);
                        sex = holder.getTextView(R.id.sex);
                        age = holder.getTextView(R.id.age);
                        starttime = holder.getTextView(R.id.startTime);
                        workname=holder.getTextView(R.id.workname);


                        room1.setText(recyclerViewHelper.list.get(position).getRoom1());
                        bed.setText(recyclerViewHelper.list.get(position).getBed());
                        name.setText(recyclerViewHelper.list.get(position).getName());
                        sex.setText(recyclerViewHelper.list.get(position).getSex());
                        age.setText(recyclerViewHelper.list.get(position).getAge());
                        workname.setText(recyclerViewHelper.list.get(position).getWorkName());
                        starttime.setText(recyclerViewHelper.list.get(position).getStartTime());

                    }
                })
                .initRecyclerView();

        /** 添加日期条目 item */
        final View dateStart = LayoutInflater.from(this).inflate(R.layout.time_select_item, (ViewGroup) getWindow().getDecorView(),false);
        dateStart.setOnClickListener(timeClick);
        container.addView(dateStart);
        View dateEnd = LayoutInflater.from(this).inflate(R.layout.time_select_item, (ViewGroup) getWindow().getDecorView(),false);
        dateEnd.setOnClickListener(timeClick);
        ((TextView)dateEnd.findViewById(R.id.text)).setText("结束时间");
        container.addView(dateEnd);
    }
    /** 日期选择点击 */
    private View.OnClickListener timeClick = new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            new SlideDateTimePicker.Builder(getSupportFragmentManager())
                    .setListener(new SlideDateTimeListener() {
                        @Override
                        public void onDateTimeSet(Date date) {
                            SimpleDateFormat formatter  = new SimpleDateFormat("yyyy年MM月dd日-HH:mm:ss");
                            String time = formatter.format(date);
                            ((TextView)v.findViewById(R.id.time)).setText(time);
                        }
                    })
                    .setInitialDate(new Date())
                    .setIs24HourTime(true)
                    .build()
                    .show();
        }
    };
}
